I have heard from a great master of Kabbalah a way to remove foreign thoughts during prayer. Before you pray, pass your right hand over your brow three times, and each time say the verse from Psalms [51:12], "Create in me, O God, a pure heart, and renew within me an upright spirit." If a foreign thought comes to you during a prayer when you are not permitted by halacha to interrupt [verbally], be quiet for a minute, pass your hand over your brow, and say this verse mentally. Then immediately you will be able to pray with kavvanah.

Kitzur Shnei Luchot ha-Brit in Jewish Spiritual Practices by Yitzhak Buxbaum