Are motives all that matter to God or do actions matter too? We read in James that faith without works is dead. So what good is my good motive if it is not acted upon?
We are judged by what we do, qualified by why we acted as we did.
"For we must all appear before the judgment seat of Christ, that each one may receive the things done in the body, according to what he has done, whether good or bad" (II Corinthians 5:10).
"Therefore judge nothing before the time, until the Lord comes, who will both bring to light the hidden things of darkness and reveal the counsels of the hearts. Then each one's praise will come from God" (I Corinthians 4:5).
There are times when people do the right thing, but they do it with improper motives. As an example: "Some indeed preach Christ even from envy and strife, and some also from good will: The former preach Christ from selfish ambition, not sincerely, supposing to add affliction to my chains; but the latter out of love, knowing that I am appointed for the defense of the gospel" (Philippians 1:15-17). Even though some preached for the wrong reason, Paul found a reason to rejoice in the fact that still Christ was being taught to people. Yes, those who did the right thing for the wrong reason would eventually give an account of themselves to God, but meanwhile, the gospel was being spread.
What Paul warns in I Corinthians 4:5 is that we, as people, can only look at what a person does. We can't guess as to why someone acts as they do. We need to keep our limitations in mind.