"If you take your friend's garment as a security you shall return it to him before sunset. For it alone is his clothing - it is his garment for his skin, and in what should he lie down? - If he will cry out to Me I will listen for I am compassionate" (Shemos 22, 25-26). The Ramban explains, that Hashem is cautioning those who think that they have the ability to take a garment of an unrighteous person as a security because even if the borrower cries out, Hashem will not heed his prayers. Therefore, the pasuk stresses that He will listen for He is compassionate. Since Hashem is compassionate, He accepts the prayers of even those who are not righteous and deserving.
Rav Wolbe (Shiurei Chumash) states that according to this explanation of the Ramban, there is a pasuk in the Torah explicitly informing us that acceptance of a tefilla is not dependent entirely on one's level of righteousness. One cannot be sure that the tefilla of a tzaddik will be accepted while that of a rasha will remain unanswered. However, as written in Tehillim, there is one prerequisite to tefilla. "Hashem is close to all those who call upon Him - to all who call upon him truthfully." In other words, one must not fool himself while davening. When praying to Hashem, a rasha must acknowledge the fact that he is wicked, but nevertheless plead to Hashem to help him in his time of distress. He knows where he stands spiritually, but still recognizes that the Hashem is the only One Who can truly help him.
Additionally, "true prayer" implies that there must be a possibility that the prayer can be fulfilled. If one prays that he should know the entire Shas by the next morning, there is a lack of truth in his prayer because such a feat is impossible.
Despite our shortcomings, Hashem takes an interest in our prayers, and He accepts them. One must never think, "Why should I daven; after all who am I that Hashem should listen to my prayers?" The Torah tells us that Hashem is "Chanun" - compassionate. The Ramban writes, "chanun" stems from the root word "chinom" - gratis. Hashem listens to our prayers for free - even though we have nothing to offer in the way of righteousness.