From what I’ve heard from priests, other devout Catholics, and Catholic radio your method is the exact right one! It’s akin to Matthew 16 where Jesus said “Get behind me, Satan!” when Peter told him he would not die.
I’ve dealt with your EXACT situation and used the exact same method to beat it. I’ve found that by asking for God to help those thoughts not enter my head and/or the grace to tell them to leave I all but beat the problem over the course of several months. That was probably 7-9 months ago and it’s gotten much easier. Not to say that I don’t have new problems now, but I think it was a growth process.
Don’t get discouraged for you may or may not ever be able to get rid of the initial thoughts. However, the sin does not come in until you dwell on them and indulge them. However, don’t take my word for it, there is no replacement for a priest and confession.