One who dons Tefillin must beware not to entertain erotic thoughts of women. [This applies even to one’s own wife.] If he is unable to wear Tefillin without such thoughts then it is better for him not to put them on at all. However this only applies if one knows for certain that he will be troubled by such thoughts; if there is only a doubt then one should not refrain from fulfilling the Mitzvah of Tefillin. [Nevertheless, even such a person that knows for certain will be troubled by erotic thoughts, must try to clear his mind to the point that he is able to put on Tefillin, and if he does not do so, he will be held accountable for causing this exemption.]
If one is having such thoughts while wearing Tefillin, are the Tefillin to be removed?
No, one is not obligated to remove his Tefillin, and rather is to try his best to remove such thoughts from his mind.
May people that are defined as Reshaim put on Tefillin?
Yes. In fact Hashem desires that Reshaim put on Tefillin even more than Tzaddikim , and it is specifically for Reshaim that the Mitzvah was given, in order to direct them to the proper path, and they need this Mitzvah even more than the Tzaddikim.
 38/4; Michaber/Rama 38/4
 Admur ibid; Michaber ibid
 Salmas Chaim 44
 Admur ibid; Rama ibid; See Kaf Hachaim 38/13
Other Poskim: Some Poskim rule he is obligated to wear Tefillin at least for the recital of Shema even in such a case. [Kneses Hagedola 38/2; brought in Shalmei Tzibur; Yifei Laleiv 38/3; Kaf Hachaim ibid]
 Admur ibid; M”A 38/4
 Chesed Lealafim, brought in Kaf Hachaim 38/12
 See Shulchan Hatahor 38/2
 Smag 3