Brachos 6 – ברכות ו

The Gemara says if one intended to perform a mitzvah and was prevented from doing so, he is credited as if he had actually fulfilled the mitzvah. This seems to be a bit difficult in light of the Gemara which states (Kiddushin 40a) that one is never held accountable for intending to transgress an aveira unless he actually carries out his intentions. What is the difference between a mitzvah and an aveira?