Can the function call fail in a way, assuming that castRay succeeded and the input values are correct? If yes, would it make sense to return a bool that denotes "success"?

If returning a bool is not needed, then suggest returning "intersection" directly instead of a return by reference (that's the usual style in OctoMap).