Type casting reference matrix fixed.
Merge pull request #521 from rebolek/patch-1

Type casting reference matrix fixed.