Breadcrumb Preprocess from Module
Preprocess hooks work in themes and modules. It doesn't matter where you put it, the only difference is, that modules have higher priority.

What you have to do is to work on caching. Because of the variables you put in,  you need a cache context on url.path, 

$variables['#cache']['contexts'][] = 'url.path';


That doesn't make a difference for the first run after clearing the cache, but makes sure that the hook is run for every new path.