This sounds tricky, the mind is a very difficult thing to keep clean, so don't feel you're the only one struggling with such a problem, millions of people have problems with impure thoughts.
First of all, ignore anyone who has failed to take this seriously. And don't let yourself feel that you're worthless. You are infinitely precious in God's eyes, no matter what; God's love is unconditional.
Practically speaking, I'm not quite sure what to suggest. Prayer is essential to this important, St Paul advised to pray at all occasions [literally 'without ceasing.'] I would advise you to speak to a healthcare professional that you can trust. It's not that I think you are mentally ill, [I don't] but specialists deal with all sorts of issues, they might be able to suggest a strategy. Remember, specialists have to deal with all sorts of strange issues, yours won't be the strangest by a long shot. There will most likely be a rational explanation.
I will pray for you.