Daniel Listhaus explains based on Ma'bit (Beis Elokim, Sha'ar Ha'yesodos 42) that
as the Gemara says, it is truly impossible to reward a mitzva in this world
so that
when it comes to those who are being rewarded or punished in this world, it must be that their rewards and punishments are not actually from keeping or transgressing the Torah but rather for doing other things. What are these other things? What is there to be rewarded or punished for if not the based on the Torah? The answer is that rewards in this world are for people who do mitzvos shelo lishma.
And
when we do the mitzvos in this fashion, we are not truly fulfilling the mitzvos in the way they are supposed to be done commanded from the Olam Ha'Elyon, and therefore the reward for doing mitzvos in this way does not come from there either.
(See Gemara Berachos 7a): The tzaddik gamur (complete tzaddik) experiences only good in both this world and the next, while the rasha gamur experiences only bad in both worlds. When it comes to the gray area in the middle, it depends on who you really are which will define the rest of your actions. The semi-rasha who happened to have done a few mitzvos clearly does not care about the mitzvos as being direct commandments from Hashem, otherwise he would have tried to work himself towards being a tzaddik. Therefore, although his good deeds require reward, they will be rewarded for in this world. However, the semi-tzaddik who spends his life working towards the right side of the spectrum, although he may have a number of aveiros on his list, those will be punished in this world rather than in the next world because they are really lower-leveled aveiros since they were not done purposely or specifically to go against the word of Hashem.