I can laugh heartily now, especially since I have just read that this failure of our cognitive systems is not altogether unusual. In fact, rehearsing what we see when these failures occurs is the basis of some kinds of humour. Enjoy: How to Think, Say, or Do Precisely the Worst Thing for Any Occasion.
But now you are saying: OK, Bill, what can we do about it? To a question like that, let me give you a firm "I'm not altogether sure."
I do not think that suppressing the untoward thoughts will help. Suppressing them might actually make them more likely to intrude. The most promising approach that I know of involves what has been called "mindfulness." I don't need to say much because there's a collection of videos on youtube that you can watch.
Here's one that I like: Mindfulness with Jon Kabat-Zinn. You can poke around on youtube for items that might appeal to you more.
If you do try this approach I'd be very interested in hearing how well it works for you.