My attempt to construct transformation matrix using 3 vertices (didn't work, need help)
As answered by batfinger in the comment. Just change the last line to 

obj.matrix_wolrd = m


everything works well now. Thanks!