In Sefer HaMinhagim, it explains what can be done as a preparation for prayer:
To dispel whatever may hamper the acceptability of one’s prayers, charity should be given beforehand. Thus we find that before praying Rabbi Eliezer would give a pauper a coin, in the spirit of the verse, “With tzedek (‘righteousness’; cf. tzedakah — ‘charity’) shall I behold Your countenance.”3 For accusatory voices On High adjudge whether a worshiper is indeed worthy of entering the heavenly palace of the King of Kings in prayer. Yet “charity rescues...,”4 and “charity elevates a nation....”5
On a general note, the Alter Rebbe discusses in great length (Likutei Amarim, chapter 12 and 28 for example), what can be done to "push away" foreign thoughts:
The concepts explained below apply to during-prayer, but can also be applied before prayer. When a foreign thought occurs, try not to dwell on it. Try to "push" it away.
The Alter Rebbe in his Tanya (Likutei Amarim, chapter 28) explains:
Even if there occur to him lustful imaginations or other extraneous thoughts during Divine Service, in Torah or in devout prayer, he must not let his heart dwell on them but must immediately avert his mind from them.
On this concept, the Baal Shem Tov (Tzava'at Harivash, section 87) explains how this should be done:
Thus if you are not praying with hitlahavut (ardor; fervor), 2 start to pray intensely. When you pray with hitlahavut, consider the nature of the [alien] thought: 3 if it relates to evil love, such as sensuous lust, bring it to its [ultimate] source which is the love of God.
In section 64 from Tzava'at Harivash, the Baal Shem Tov explains that sometimes, a foreign though occours while praying, only because of the concept "descent for the sake of an ascent"
Such a test, e.g. a foreign thought "popping up into your head during prayer", is only because G-d wants us to be stronger and therefore tests us with this.
See also Tanya, Likutei Amarim, chapter 12:
However, the impression retained in his mind from his meditation, during prayer, on G‑d’s greatness, and the [natural] love and fear of G‑d hidden in the right part of his heart, enable him to prevail over and dominate the evil [animal soul’s] craving, preventing the evil from gaining the supremacy and dominion over the “city” (the body) and carrying out its craving from the potential to the actual by clothing itself in the organs of the body in actual speech or deed.