I’ve been looking for some help with this filter too and came across your post. It’s been a while but in case you’re still working on it,
I think you need to include global $bp;
function ssviewed_user_id( $user ) {
global $bp;
return $bp->displayed_user->id;
}
add_filter( 'bp_group_widget_user_id', 'ssviewed_user_id', 10, 3 );
For the record, I think it should return an integer, so your $user_id = ‘2’ should have been $user_id = 2;
Good luck!