I think you're pretty naive to assume your 17 year old son won't be in a position where he could be meeting a woman in her twenties. If not a club then a pub, general social activities in your area - bowling, roller skating, meet and mingle groups for young people.
Unfortunately with modern social media methods we have to guide our children more appropriately. Gone are the days when you have someone your number and that was the only way (other than stalking in person) to find anything else out about them.
Did your son give the woman his Instagram name or did she find him through tagging etc?
At 17 I don't think your son is any less complicit in the teacher's messages, especially if he is replying with suggestive comments like wishing he was in bed with her. However, I would suspect that this is likely to be teen bravado rather than actual intent.
Ultimately, talk to your son and explain why the messages from both of them really aren't appropriate at the moment. Use what you learn from that conversation to guide your next steps - ie son tells you he and teacher have been Instagram followers since school days, not appropriate and further undertones of grooming behaviour. Decide whether to approach teacher in the first instance and advise her to cease contact or you will be letting the school know, or go straight to the school without giving the warning.
If he says they've only recently been in touch then advise your son that it might not be an entirely appropriate friendship at this stage due to her recent teaching of him and advise him to put a stop to the flirty chat and if the teacher then continues, follow appropriate route.