The use keyword is what you need:
$id = 3;
DB::transaction(function($id) use ($id) {
DB::table('users')->where('id', '=', $id)->get();
});
For PHP 7 (untested, edited as requested by the answer below):
$id = 3;
DB::transaction(function() use ($id) {
DB::table('users')->where('id', '=', $id)->get();
});