this is rewrite of the github patch #674 by chouclee; the goal is to improve polyfit accuracy
Merge pull request #1529 from vpisarev:polyfit_accuracy_2