...there are many works in the world which are good to men but not good to God since they are not done aright. Prov. 14:12: There is a way which seemeth just to a man: but the ends therefore lead to death. Eccles. 8:10: I saw the wicked buried: who also when they were yet living were in the holy place, and were praised in the city as men of just works. But this is manifested by right faith when it attains its reward from God, Who does not remunerate except right things.
[Thomas Aquinas, Commentaries on St. Paul's Epistles to Timothy, Titus, and Philemon, Baer, tr. St. Augustine's Press (South Bend, IN: 2007) p. 200. This is from the commentary on Philemon.]