How to pass computed data from Theme preprocess functions to Twig templates?
$variables is an array, not an object.

But yes, it's the one and only way to pass additional data to the template. Anything you put in there is available in the template then. $variables['hello'] = 'world'; can be printed with {{ hello }}.