Hello and thanks for your question. I'm Dr. Hasan and I'll try to help you.
I am going to address your primary concern but i will answer anything you want to ask later.
No you are not at risk of getting worms this way.
Yes contaminated water can cause transmission of worms.
But you just washed your mouth and didn't swallow the water so you are not at any risk of getting worms this way.
Please don't stress yourself.
I wish you all the best for a healthy life. My goal is to provide you with excellent service – if you feel you have received anything less, please reply back as I am happy to address follow-up questions. Kindly rate me when you are done. You can come back here to ask anything even after you have rated the answer. I will be glad to help you always.