Fix multi threading by using const ref to function See merge request !3318
mentioned in commit ff1ef898
mentioned in commit adaab5f9