[Fix #7618,Fix #4761] - Distance Matrix entries are only calculated for the first feature

I believe this issue was due to the existence of two iterators pointing to the same layer was causing OgrIterator to close. Please review and comment if this is the right method to fix this issue. Also fixes  http://hub.qgis.org/issues/4761 which existed from QGIS 1.8. Unfortunately, I did both fixes in a single commit. I can try to separate them if required.