St. Thomas writes (Summa Theologica II-II q. 83 a. 13 ad 3) that "to wander in mind unintentionally [during prayer] does not deprive prayer of its fruit."
We should listen to Paul and submit all our thoughts and ideas and feelings about God and about life to Paul’s teaching (as God’s apostle) for scrutiny. And if anything is out of sync with Paul’s teaching, we should let it be destroyed. When we put our minds and thoughts at the disposal of Apostolic teaching (honestly) and say, “Anything in my thinking that needs to be destroyed, destroy it,” that can utterly undo you. There will be seasons in life where we will be troubled and fight against the dismantling of what we feel are really important structures in our world view and thought life. So, I think that is the first thing we do. We listen to Paul. We submit everything we think — all our ideas, all our worldview, all our viewpoints — to God, and we say, “Let your word dismantle me if necessary.” with the result of restoration, revelation and Spiritual discernment.
Human brain has 30 billion cells called neurons. Each cell is connected to millions of other cells through outgoing projections called dendrites. Communication takes place through ' firing' of neurons. Thoughts are the result of such communication. Prayer, as a matter of fact, is a strain of connected spiritual thoughts. Unfortunately, there is no specific area in brain which creates only those thoughts which help us pray. Even if one per cent of the brain cells are at work during prayer, they are sure to create multiple number of thoughts, which we call distraction. The more we try to ' scare away' distractive thoughts, the deeper they get embedded in the thought process. It is wiser to ignore those thoughts- be they good or bad- and ' let sleeping dogs lie'. Once you come back from prayer, you can identify those distractive thoughts . You may either put them to good use, or just forget them. In the third alternative, you can ' connect ' such distracting thoughts to spiritual ideas through a conscious exercise, so that when you sit down to pray on subsequent occasions, and are troubled by distracting thoughts , they automatically get channelised to spiritual thoughts. As for ' original thoughts ' which form the basis of innovative ideas, they can come up anytime of the day, even during prayer, and also through dreams when we are asleep. Whether they are distractions or not, is to be decided on merit of each case.