ספר המדות Improper Thoughts / Part II · ג
Sefer HaMiddot 795
ג. לְהִרְהוּרֵי עֲבוֹדָה זָרָה יַעֲלֶה עַל מַחֲשַׁבְתּוֹ וִיקַבֵּל עַל עַצְמוֹ, שֶׁיַּעֲסֹק בִּגְמִילוּת־חֲסָדִים וְעַל־יְדֵי זֶה יִתְבַּטֵּל מֵהִרְהוּרֵי עֲבוֹדָה זָרָה.
3. Regarding thoughts of idol worship, one should rouse in one's mind and one should accept upon himself to get involved in acts of kindness, and through this, he will be nullified from thoughts of idol worship.