http://revach.net/article.php?id=3310

Section:  Avodah   Category: Tefila
The Shela HaKadosh: A Few Swipes Free The Mind
A segula is brought down in the name of the Shela HaKadosh for clearing the mind prior to davening.  He says you should pass your right hand over your forehead three times.  Each time you should say (Tehilim 51:12), "Lev Tahor Bira Li Elokim V'Ruach Nachon Chadesh Bikirbi; Create in me a pure heart, and renew a constant spirit inside me."  If a foreign thought interrupts your davening after you've already started, you should stop davening for a moment, pass your right hand over your forehead three times, and think this pasuk to yourself.  The Debriciner Rov says (Be'er Moshe 2:3) that even a lefty should use his right hand.

The Baalei Mussar say that you are not guilty if a foreign thought comes into your mind suddenly.  However, it is your responsibility to send it right back out with letting it linger.

The Kotzker Rebbe had a big problem with the concept of Machshavos Zoros or foreign thoughts.  He wondered why it was called "foreign" if it comes from the person himself???